#include "BaseWall.h"

#include <Ogre.h>
#include "DefaultCube.h"
#include "BtOgrePG.h"
#include "BtOgreGP.h"
#include "BtOgreExtras.h"

using namespace Ogre;

BaseWall::BaseWall(Ogre::String name, Ogre::Vector3 size, Ogre::Vector3 pPos, Ogre::SceneManager* sceneMgr)
{
	m_pSceneMgr = sceneMgr;
	m_WallCube = new DefaultRectangle("SimpleCubeO1", size, Ogre::ColourValue(1.0,1.0,1.0,1.0));
	m_WallCube->setCastShadows(true);

	MeshPtr mesh;
	mesh = m_WallCube->convertToMesh("CubeMesh" + name);
	mesh->buildEdgeList();
    mesh->prepareForShadowVolume();

	m_WallEntity =  m_pSceneMgr->createEntity(name, "CubeMesh" + name);
	m_WallNode = m_pSceneMgr->getRootSceneNode()->createChildSceneNode();

	m_WallNode->attachObject(m_WallEntity);
    m_WallNode->setPosition(pPos);

	 //Create shape.
	BtOgre::StaticMeshToShapeConverter converter(m_WallEntity);
    m_WallShape = converter.createConvex();

    //Create BtOgre MotionState (connects Ogre and Bullet).
    WallState = new BtOgre::RigidBodyState(m_WallNode);

    //Create the Body.
    m_WallBody = new btRigidBody(0, WallState, m_WallShape, btVector3(0,0,0));
}


BaseWall::~BaseWall(void)
{
}
